package com.woniuxy.mapper;

import com.work.framework.pojo.City;
import com.work.framework.pojo.County;
import com.work.framework.pojo.Site;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;

import java.util.List;

/**
 * @author Administrator
 * @title: SiteMapper
 * @projectName mashangpai
 * @description: TODO
 * @date 2019/9/1714:43
 */
@Mapper
@Repository
public interface SiteMapper extends BaseMapper<Site> {

    /**
     * 查询所有省市
     *
     * @return list<city></>
     */
    @Select("select * from city")
    List<City> findCities();

    /**
     * 查询省市对应的市区
     *
     * @param cityid
     * @return list<County></>
     */
    @Select("select * from county where cityid=#{cityid}")
    List<County> findCountiesByCityId(Integer cityid);

    /**
     * 添加收货地址
     *
     * @param site
     * @return
     */
    @Insert("INSERT INTO site (uid,consignee,consigneeNum,consigneeAddress)VALUES(#{uid},#{consignee},#{consigneeNum},#{consigneeAddress})")
    Integer insertSite(Site site);

    /**
     * 查询用户收货地址
     *
     * @param uid
     * @return
     */
    @Select("select * from site where uid = #{uid} and flage !=0")
    List<Site> findSitesByUid(Integer uid);

    /**
     * 删除收货地址
     *
     * @param site
     * @return
     */
    @Update("update site set flage = #{flage} where sid =#{sid}")
    Integer deleteSite(Site site);

    /**
     * 当前订单收货地址
     * @param sid
     * @return
     */
    @Select("select * from site where sid = #{sid} and flage != 0")
    Site findSiteBySid(Integer sid);

    /**
     * 设置全部对象地址为普通地址
     * @param uid
     * @param flage
     */
    @Update("update site set flage = #{flage} where uid =#{uid} and flage != 0")
    void update(Integer uid, int flage);
}
